package com.weixin.lambda;

import org.junit.Test;

import java.util.function.Consumer;

/**
 * @ClassName LambdaTest
 * @Description
 * @date 2022/2/21 14:51
 * @author: wx
 * @Version 1.0
 */
public class LambdaTest {

    @Test
    public void test() {
        //1.无参
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("i love tam");
            }
        };
        runnable.run();
        System.out.println("-------------------------->");
        Runnable runnable1 = () -> System.out.println("i love you");
        runnable1.run();
        System.out.println("-------------------------->");

        //2.一个参数无返回值
        Consumer<String> consumer = new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        };
        consumer.accept("what is lie or truth  different ?");
        System.out.println("-------------------------->");
        Consumer<String> consumer1 = (s -> {
            System.out.println(s);
        });
        consumer1.accept("the lie is believe by the listener,the truth is believe by sayer");
        System.out.println("-------------------------->");
        consumer.accept("what is lie or truth  different ?");
        Consumer<String> consumer2 = (System.out::println);
        System.out.println("-------------------------->");

        //3.省略形参类型，使用类型推断

        //4.一个参数括号可省略

        //5.多参数带返回值

        //6.多参单条语句大括号，return可省略

    }

}
